package com.openness.spider.commons;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.List;

import org.apache.hadoop.hbase.util.Bytes;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.data.ACL;

/**
 * @author Rain
 * @version 2013-6-20 上午10:34:52
 */

public class Statics {

	public static final String HOSTNAME;

	static {
		try {
			HOSTNAME = InetAddress.getLocalHost().getHostName();
		} catch (UnknownHostException e) {
			throw new ExceptionInInitializerError("can't get hostname: "
					+ e.toString());
		}
	}

	public static final String DIGEST_ALGORITHM = "MD5";

	public static final Charset DEFAULT_ENCODE = Charset.forName("UTF-8");

	/*
	 * HBase
	 */
	public static final String HBASE_MASTER = "hbase.master";

	public static final String HBASE_ZOOKEEPER_QUORUM = "hbase.zookeeper.quorum";

	public static final String HBASE_ZOOKEEPER_PROPERTY_CLIENTPORT = "hbase.zookeeper.property.clientPort";

	public static final byte[] HBASE_FAMILY = Bytes.toBytes("baseinfo");

	public static final String HBASE_TABLE_WORKQUEUE = "workqueue";

	public static final String HBASE_TABLE_PROCESSQUEUE = "processqueue";

	public static final String HBASE_TABLE_HISTORY = "history";

	public static final String HBASE_TABLE_SPIDERDATA = "spiderdata";

	/*
	 * ZK
	 */
	public static final String ZK_SEPERATOR = "/";

	public static final byte[] EMPTY_BYTEARRAY = new byte[0];

	public static final List<ACL> ACL = Ids.OPEN_ACL_UNSAFE;

	public static final CreateMode CREATEMODE_PERSISTENT = CreateMode.PERSISTENT;

	public static final CreateMode CREATEMODE_EPHEMERAL_SEQUENTIAL = CreateMode.EPHEMERAL_SEQUENTIAL;

	public static final String ZK_SPIDER = "/spider";

	public static final String ZK_SPIDERS_NODE = "/spider/spiders";

	public static final String ZK_SPIDERS_NODE_SUFFIX = "/spider/spiders/spider_";

	public static final String ZK_LOCK_NODE = "/spider/lock";

	public static final String ZK_THREADS_NODE = "/spider/threads";

	public static final String ZK_THREADS_NODE_SUFFIX = "/spider/threads/thread_";

	public static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm");

	public static final String ROWKEY_SEPERATOR = "_";

}
